#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @File   : e_multiprocessing_subprocess.py
# @Email  : xuexia_xu@feidee.com
# @Time   : 2024/4/2 17:11
# @Desc   : 子进程???

"""
subprocess模块可以让我们非常方便地启动一个子进程，然后控制其输入和输出。
"""
import subprocess

# print('$ nslookup www.python.org')
# r = subprocess.call(['nslookup', 'www.python.org'])
# print('Exit code:', r)

print('$ nslookup')
p = subprocess.Popen(['nslookup'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, err = p.communicate(b'set q=mx\npython.org\nexit\n')
print(output.decode('gbk'))
print('Exit code:', p.returncode)
